import tempfile

tf = tempfile.NamedTemporaryFile(delete=False)
try:
    tf.write(b'Some data')
finally:
    tf.close()

print(tf.name)  # 打印临时文件名以便稍后访问此文件